var Page = function(){
    this.init();
};
Page.prototype = {
    params: {
        passport: ''
    },
    init: function(){
        this.initParams();
        this.initEvent();
    },
    initParams: function(){
        this.params.passport = Pub.getCookie('_PASSPORT');
    },
    getData: function(){
        var _this = this;
        var paramsObj = {
            passport: _this.params.passport
        };
        Api.memberdetails(paramsObj, function(data){
            console.log(data);
            $('#adminName').val(data.loginAccount);
            $('#adminEmial').val(data.emial);
            if (data.headPortrait!='') {
                $('#headImg').removeClass('Hui-iconfont-avatar');
                $('#headImg').html('<img id="headPortrait" style="width:72px;height:72px" src="'+data.headPortrait+'" alt="">');
            };
        });
    },
    uploadImg: function(){
        var _this = this;
        Api.upload('#up_form1','#file_1', 'headimgurl',_this.params.passport, function(response){
            console.log(response);
            if(response.code === 0){
                $('#headImg').removeClass('Hui-iconfont-avatar');
                $('#headImg').html('<img id="headPortrait" style="width:72px;height:72px;" src="'+response.data.imgUrl+'" alt="">');
            }
        });
    },
    submit:function(){
        var _this = this;
        $('#submit').click(function(event) {
             var headPortrait='';
            if ($('#headPortrait')) {
                headPortrait=$('#headPortrait').attr('src');
            };
            var oldPwd=$('#oldPwd').val();
            var newPwd=$('#newPwd').val();
            var confirmPwd=$('#confirmPwd').val();

            var paramsObj = {
                passport: _this.params.passport,
                headPortrait:headPortrait,
                password:oldPwd,
                newPassword:newPwd,
                newPasswordTo:confirmPwd
            };
            console.log(paramsObj);
            Api.membermodifypwd(paramsObj, function(data){
                console.log(data);
                layui.use('layer', function(){
                     layer.msg('提交成功', {icon: 6});
                 });
                setTimeout(function(){
                    window.location.reload();
                }, 1000)
            });
        });
    },
    initEvent: function(){
        var _this = this;
        _this.getData();
        _this.submit();
        _this.uploadImg();
    }
};
var page = new Page();